﻿using GameData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TNServer
{
    public class GlobalVO
    {
        

        //角色数据
        public Dictionary<string, RoleInfo> UserDic = new Dictionary<string, RoleInfo>();

        //当前排号 可以改变
        public int CurNumber;
        public Dictionary<string, int> CurIndxDic = new Dictionary<string, int>();
        public Dictionary<string, int> CurQueneDic = new Dictionary<string, int>();
        public Dictionary<string, int> DueCallDic = new Dictionary<string, int>();
        public Dictionary<string, int> numberCountdic = new Dictionary<string, int>();


        //当前处理数
        public int CurDueNum;
        //当前抽中数
        public int CurPickNum;

        public void SetPickNum(int value)
        {
            CurQueneDic[SetDataDic["批次"]] = value;
        }

        public int GetPickNum()
        {
            return CurQueneDic[SetDataDic["批次"]] ;
        }

        //当前可显示个数
        public int ShowNum;
        //保存时间
        public long DateTimeTicks;
        //
        public List<NumberInfo> AllRDic = new List<NumberInfo>(); 
        //抽中的号码
        public List<NumberInfo> PickDic = new List<NumberInfo>();
        //放弃的号码
        public List<NumberInfo> CancleDic = new List<NumberInfo>();
        //处理中的号码
        public List<NumberInfo> DueDic = new List<NumberInfo>();
        //完成的号码数
        public List<NumberInfo> ComplectDic = new List<NumberInfo>(); 
        //VIP客户--必定抽中
        public List<NumberInfo> VipDic = new List<NumberInfo>(); 
        //一次抽号数量
        public int PickNum;
        //
        //
        //
        //号码数据
        //领取中的号码
        public List<NumberInfo> ReceiveDic = new List<NumberInfo>();
        //客户
        public Dictionary<string, CustomerData> CustomerDatas = new Dictionary<string, CustomerData>();
        //新客户
        public Dictionary<string, CustomerData> NewCustomerDatas = new Dictionary<string, CustomerData>();
        //开盘名称
        public string trunName;
        //
        public Dictionary<string,string> SetDataDic = new Dictionary<string, string>(); 
        //批次
        public List<string> batchList = new List<string>();
        public List<string> enList = new List<string>();
        //已经排位
        public Dictionary<string, List<NumqueInfo>> HasPaiweiList=new Dictionary<string, List<NumqueInfo>>();

        public Dictionary<string,List<int>> PickNUmDic = new Dictionary<string, List<int>>();

        public PickNumInfo PickNumInfo;
        //
        //
        public string startCallGrpup;

        public SoundType SoundType;
        //
        public bool isNumRec = true;

        public GlobalVO()
        {
            CurNumber = 0;
            CurDueNum = 0;
            ShowNum = 5;
            CurPickNum = 0;
            PickNum = 5;
            SoundType = new SoundType();
            SoundType.putonghua = true;
            SoundType.yueyu = false;
            isNumRec = true;
            enList.Add("A");
            enList.Add("B");
            enList.Add("C");
            enList.Add("D");
            enList.Add("E");
            enList.Add("F");
            enList.Add("G");
            SetDataDic.Add("连号","否");
            SetDataDic.Add("当前标识", "A");
            SetDataDic.Add("开始抽号", "否");




        }

        //当前号码
        public int CurIndex()
        {
            return CurIndxDic[SetDataDic["批次"]];

        }

        public void SetCurIndex(int value)
        {
            CurIndxDic[SetDataDic["批次"]] = value;
        }


        public void SetCurIndx(string group, int value)
        {
            if (CurIndxDic.ContainsKey(group))
            {
                CurIndxDic[group] = value;
            }
        }

        public int GetCurIndx(string group)
        {
            if (CurIndxDic.ContainsKey(group))
            {
                return CurIndxDic[group];
            }
            return -1;
        }

        /// <summary>
        /// 获取标识
        /// </summary>
        /// <param name="globalVo"></param>
        /// <param name="bathstr"></param>
        /// <returns></returns>
        public  string GetGroupTag(string bathstr="")
        {
            if (bathstr == "")
            {
                return "A";
            }
            if (!SetDataDic.ContainsKey("批次"))
            {
                return "A";
            }
            else
            {
                if (batchList.Contains(bathstr))
                {
                    int indx = batchList.IndexOf(bathstr);
                    if (enList.Count>=indx)
                    {
                        return enList[indx];
                    }
                }
                return "A";
            }
            return "A";
        }


        public void AddBatchlistItem(string str)
        {
            if (!batchList.Contains(str))
            {
                batchList.Add(str);
                CurIndxDic[str] = 0;
                CurQueneDic[str] = 0;
                numberCountdic[str] = 0;
                DueCallDic[str] = 0;
                HasPaiweiList[str] = new List<NumqueInfo>();
                PickNUmDic[str] = new List<int>();

                if (!SetDataDic.ContainsKey("批次"))
                {
                    SetDataDic.Add("批次", str);
                }

            }

        }


        public void AddSetData(string key, string value)
        {
            if (SetDataDic.ContainsKey(key))
            {
                SetDataDic[key] = value;
            }
            else
            {
                SetDataDic.Add(key,value);
            }
        }


        public bool CheckSetData(string key,string value)
        {
            return SetDataDic.ContainsKey(key) && SetDataDic[key].Equals(value);
        }


        public bool checkNumInDic(List<NumberInfo> dic, NumberInfo num)
        {
            int count = dic.Count;
            NumberInfo temp = null;
            for (int i = 0; i < count; i++)
            {
                temp = dic[i];
                if (temp.@group==num.@group && temp.value == num.value)
                {
                    return true;
                }
            }

            return false;

        }







        public bool checkInPick(NumberInfo numberInfo)
        {
            return checkNumInDic(this.PickDic,numberInfo);

        }

        public bool checkInDue(NumberInfo numberInfo)
        {
            return checkNumInDic(this.DueDic, numberInfo);

        }

        public bool checkInVIP(NumberInfo numberInfo)
        {
            return checkNumInDic(this.VipDic, numberInfo);

        }

        public bool checkInRec(NumberInfo numberInfo)
        {
            return checkNumInDic(this.ReceiveDic, numberInfo);

        }

        public bool checkInComplete(NumberInfo numberInfo)
        {
            return checkNumInDic(this.ComplectDic, numberInfo);

        }

        public bool checkInCancle(NumberInfo numberInfo)
        {
            return checkNumInDic(this.CancleDic, numberInfo);

        }


        public NumberInfo GetNumInDic(List<NumberInfo> dic, int value,string groupname="")
        {
            int count = dic.Count;
            NumberInfo temp = null;
            for (int i = 0; i < count; i++)
            {
                temp = dic[i];
                if (temp.value == value && temp.@group == groupname)
                {
                    return dic[i];
                }
            }

            return null;
        }


        public NumberInfo GetInPick(int value)
        {
            return GetNumInDic(this.PickDic, value);
            
        }

        public NumberInfo GetInDue(int value)
        {
            return GetNumInDic(this.DueDic, value);

        }
        public NumberInfo GetInVIP(int value)
        {
            return GetNumInDic(this.VipDic, value);

        }
        public NumberInfo GetInRec(int value,string groupname)
        {
            return GetNumInDic(this.ReceiveDic, value, groupname);

        }
        public NumberInfo GetInComplete(int value)
        {
            return GetNumInDic(this.ComplectDic, value);

        }
        public NumberInfo GetInCancle(int value)
        {
            return GetNumInDic(this.CancleDic, value);

        }





        /// <summary>
        /// 添加角色数据
        /// </summary>
        /// <param name="username"></param>
        /// <param name="rf"></param>
        /// <returns></returns>
        public bool AddRoleInfo(string username,RoleInfo rf)
        {
            if(!UserDic.ContainsKey(username))
            {
                UserDic.Add(username, rf);
            }

            return false;
        }

        /// <summary>
        /// 获取角色数据
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public RoleInfo GetRoleInfo(string username)
        {
            if (UserDic.ContainsKey(username))
            {
                return UserDic[username];
            }
            return null;
        }

        /// <summary>
        /// 加到领取号码中
        /// </summary>
        /// <param name="nf"></param>
        /// <returns></returns>
        public bool AddNumToReceive(NumberInfo nf)
        {
            if(!ReceiveDic.Contains(nf))
            {
                ReceiveDic.Add(nf);
            }
            return false;

        }

        /// <summary>
        /// 添加到领取号码中
        /// </summary>
        /// <param name="nf"></param>
        /// <returns></returns>
        public bool AddNumToPick(NumberInfo nf)
        {
            if (!PickDic.Contains(nf))
            {
                PickDic.Add(nf);
            }
            return false;

        }

        /// <summary>
        /// 取消号码队列
        /// </summary>
        /// <param name="nf"></param>
        /// <returns></returns>
        public bool AddNumToCancle(NumberInfo nf)
        {
            if (!CancleDic.Contains(nf))
            {
                CancleDic.Add(nf);
            }
            return false;

        }
        /// <summary>
        /// 处理号码队列
        /// </summary>
        /// <param name="nf"></param>
        /// <returns></returns>
        public bool AddNumToDue(NumberInfo nf)
        {
            if (!DueDic.Contains(nf))
            {
                DueDic.Add(nf);
            }
            return false;

        }

    }
}
